package com.thread.sync.sync09;

public class ExectorsTest {

    public static void main(String[] args) {
        //创建一个有10个线程的线程池,任务多于10个会一直等待,直到10个线程中有空闲线程为止
        //ExecutorService pool = Executors.newFixedThreadPool(10);
        //开启线程
//		pool.execute(new Thread(()->{System.out.println(Thread.currentThread().getName()+"执行中.....");}));
//		pool.execute(new Thread(()->{System.out.println(Thread.currentThread().getName()+"执行中.....");}));
//		pool.execute(new Thread(()->{System.out.println(Thread.currentThread().getName()+"执行中.....");}));

        //创建只有一个线程的线程池
//		ExecutorService poolSingle = Executors.newSingleThreadExecutor();
//		poolSingle.execute(new Thread(()->{
//			System.out.println("run1");
//			while(true){
//			}
//		}));				
//		//下面永不会执行
//		poolSingle.execute(new Thread(()->{System.out.println("run2");}));
        //不指定数量.如果任务多,且没有空闲线程则会一直创建线程,并且空闲线程会在60秒后回收
//		ExecutorService cachePool = Executors.newCachedThreadPool();
//		cachePool.execute(new Thread(()->{
//			System.out.println("run1");
//			while(true){
//			}
//		}));
//		cachePool.execute(new Thread(()->{
//			System.out.println("run2");
//			while(true){
//			}
//		}));
    }

}
